package testingClient;

import java.io.*;
import java.net.*;

import smash_tris.*;



public class Client {

	public static void main(String[] args) throws IOException {
		System.out.println("1");
		Socket clientSocket = null;
		ObjectOutputStream out = null;
		ObjectInputStream in = null;

		Integer portNumber;
		for (String a : args) {
			System.out.println(a);
		}
		

		if (args.length == 0) {
			portNumber = 3001;
		} else {
			portNumber = Integer.getInteger(args[0]);
		}

		try {
			clientSocket = new Socket("localhost", portNumber);
			System.out.println("połączono");
			out = new ObjectOutputStream(new BufferedOutputStream(
					clientSocket.getOutputStream()));
			out.flush();
			in = new ObjectInputStream( new BufferedInputStream(
					clientSocket.getInputStream()));
			System.out.println("ok");
		} catch (UnknownHostException e) {
			System.err.println("Don't know about host: taranis.");
			System.exit(1);
		} catch (IOException e) {
			System.err.println("Couldn't get I/O for "
					+ "the connection to: taranis.");
			System.exit(1);
		}

		/*
		 * BufferedReader stdIn = new BufferedReader( new
		 * InputStreamReader(System.in));
		 */
		
		DataPacket userInput;
		
		try {
			while ((userInput = (DataPacket) in.readObject()) != null) {
				System.out.println(userInput.getTypeOfInformation());
				System.out.println("wyświetlono");
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("koniec");

		out.close();
		in.close();
		// stdIn.close();
		clientSocket.close();
	}
}
